﻿Imports System.Data
Imports System.Data.SqlClient
Imports System.IO

Module moNetwork

    Public gCnnPCE As SqlConnection
    Public gConnectionStr As String

    Dim constatus As Boolean = False
    Dim con As SqlConnection

    Public Sub SetupConnection()

        Dim ConnFilePath As String = Application.StartupPath
        If My.Settings.Conn.ToString = "" Then
            Dim frm As New SQLServer
            frm.ShowDialog()

            'InstanceName = Environment.MachineName & "\" & GetSqlServers_InstanceName()
            'AttchDataBase()
            'System.Threading.Thread.Sleep(3000)
            ''InstanceName = Environment.MachineName & "\SQLEXPRESS"
            ''InstanceName = Environment.MachineName & "\" & GetSqlServers_InstanceName()
            'gConnectionStr = "workstation id=" & InstanceName & ";packet size=4096;integrated security=SSPI;data source=" & InstanceName & ";persist security info=False;initial catalog=PRMDB"
            'gCnnPCE = New SqlConnection(gConnectionStr)

            'Dim objReader As StreamWriter
            'objReader = New StreamWriter(ConnFilePath & "\SQLServerConnection.txt")
            'objReader.Write(gConnectionStr)
            'objReader.Close()
        Else
            'Dim EntireFile As String
            'Dim oFile As File
            'Dim oRead As StreamReader
            'oRead = oFile.OpenText(ConnFilePath & "\SQLServerConnection.txt")
            'EntireFile = oRead.ReadToEnd()
            'gConnectionStr = EntireFile.Trim
            'oRead.Close()
            gConnectionStr = My.Settings.Conn
        End If


        'Dim IntanceName As String = ""
        ''IntanceName = Environment.MachineName & "\SQLEXPRESS"
        'IntanceName = ".\SQLEXPRESS"
        'gConnectionStr = "workstation id=" & IntanceName & ";packet size=4096;integrated security=SSPI;data source=" & IntanceName & ";persist security info=False;initial catalog=EXPJOBDB"
        ''gCnnPCE = New SqlConnection("Data Source=" & IntanceName & ";Initial Catalog=EXPJOBDB;Integrated Security=True")
        'gCnnPCE = New SqlConnection(gConnectionStr)

        'Try
        '    gCnnPCE.Open()
        'Catch ex As Exception
        '    AttchDataBase()
        '    System.Threading.Thread.Sleep(3000)
        '    gCnnPCE.Open()
        'End Try

    End Sub



End Module
